package com.bawei.park2211a.visit

import android.app.TimePickerDialog

import com.alibaba.android.arouter.facade.annotation.Route
import com.bawei.base.bean.AddVisitEntity
import com.bawei.base.mvvm.BaseActivity

import com.bawei.park2211a.databinding.ActivityAddVisitBinding
import com.bigkoo.pickerview.builder.TimePickerBuilder

import com.blankj.utilcode.util.ToastUtils
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat
import java.util.*

@Route(path = "/app/visit/AddVisitActivity")
@AndroidEntryPoint
class AddVisitActivity : BaseActivity<ActivityAddVisitBinding, AddVisitViewModel>() {
    private lateinit var addVisitEntity: AddVisitEntity
    private var timeYear = ""
    private var timeSec = ""
    private var sdf = SimpleDateFormat("yyyy-MM-dd")
    override fun initView() {
        addVisitEntity = AddVisitEntity()
        binding.etVisitTime.setOnClickListener {
            TimePickerBuilder(this) { date, _ ->
                binding.etVisitTime.text = sdf.format(date)
                timeYear = sdf.format(date)
            }.build().show()
        }
        binding.visitStartimeSubmit.setOnClickListener {
            val instance = Calendar.getInstance()
            val year = instance.get(Calendar.YEAR)
            val month = instance.get(Calendar.MONTH)
            TimePickerDialog(this, { _, i, i2 ->
                binding.visitStartimeSubmit.text = "${i}-${i2}"
                timeSec = "${i}-${i2}"
            }, year, month, true).show()
        }
        binding.visitEndtimeSubmit.setOnClickListener {
            val instance = Calendar.getInstance()
            val year = instance.get(Calendar.YEAR)
            val month = instance.get(Calendar.MONTH)

            TimePickerDialog(this, { _, i, i2 ->
                binding.visitEndtimeSubmit.text = "${i}-${i2}"
            }, year, month, true).show()
        }
        binding.addVisitSubmit.setOnClickListener {
            addVisitEntity.appointmentTime = "$timeYear $timeSec"
            addVisitEntity.purpose = binding.addVisitPurpose.text.toString()
            addVisitEntity.idNumber = binding.etVisitUserNumber.text.toString().toLong()
            addVisitEntity.phoneNumber = binding.etVisitPhone.text.toString().toLong()
            addVisitEntity.visitorName = binding.etVisitName.text.toString()
            addVisitEntity.plateNumber = binding.etAddVisitCarNumber.text.toString()
            addVisitEntity.employeeId = 6
            viewModel.addVisit(addVisitEntity)

        }
    }

    override fun initData() {
        viewModel.addVisitSuccess.observe(this) {
            ToastUtils.showLong("添加成功")
        }
    }
}